Hello there welcome to this video on conditional statement conditional statements are code that will
allow us to test whether an expression or condition is true and then run or executed could depending
on that condition saw form condition It's true Iran has one could.
It's not Iran.
The other code and the most common type of conditional statements in Gap a script is core.
IF ELSE state so this is an example of an IF statement code.
So I'll just explain this code for you.
So it begins with a variable and the variable name is car type B value for that variable is Range Rover.
So this is the piece of code you need to fork solidly.
If else and this is how you will write it you begin with it.
If with the word if and then you have peronne.
This is where you put in the condition so this is where you would specify the condition in between the
parentheses So the condition is if the card type which has been declared here is equals to in Javascript
double because to a means equals a single one means we all set in ungiving of giving a value.
So if card type equals to render a vat alert.
This was the code that will be executed will be this.
So a pop up window will come obscene.
I lost my range rover.
If for example the name here is wrong and this is changed to E or something then it will not match the
value here and there when the piece of code runs.
It will now execute this second part because the first part is wrong.
It will not execute alert.
I would like a render of that please.
Ah I have got the code here inside my text.
Add it up.
This is the code here.
All right.
So why is saying here.
If the card type declared here equals to wrong do I want you to alert this message.
I love my renderer if not display the second part of the code.
So this is what is busy if else.
Conditional statement does.
So let me run this code.
Hard yes it is.
I love my brain for a few minutes.
Because the first part of the code if statement is correct there is no need to run the second part.
First condition has been satisfied.
So the condition that place between the between the perowne.
This is very important.
And also dont forget the curly braces where you write in the code curly braces is very important.
So if you notice the curly braces they are highlighted Thus the first one after the if statement so
you go a B.
They always come in pairs.
Curly braces.
So this is the second braith this is a match is for the else statement.
So if the first part of the code is not met it will execute the second part.
For example if I changed the name half I change the name here say airport.
Just change your name pull rate from one end to a save.
If I run that he should give me this second part because that name is wrong.
See that has given me the second part of the code.
I would like a Range Rover please because this image if part of it Icard time is not equal to a Range
Rover because I have purposely spelt it wrong because it doesn't match the value here.
This equals sign is what determines is see value in this card type.
This variable must match this
right so this is how you would write an IF ELSE statement.
Always remember the curly braces after that.
If you need to place a curly braces on the condition is place between B parentheses.
Okay so on one condition that does it does condition is not met.
It will execute this condition which is meant to execute this piece of code here.
If it is not met it will.
Excuse this piece of code.
Some.
Got another one here written for icecream by the same the same format.
So this is just another piece of code with an if else statement.
So a variable like declare the icecream.
Give me a value off chocolate and this is each state means seeing that if the icecream variable is equal
if you notice he has got three quarters of a D is strictly equal to.
If the icecream is a double That means it was 3 it was two families strictly equals two.
If ice cream is truly equal to chocolate alert Hooray.
I love chocolate so if this is true condition is true it will run its course.
If it is not true it will run the second code.
So let me run.
That's where it should run but could.
Key something awesome to run with the call.
Let's have a look.
All right.
I figured out what was wrong with a cold.
Well done.
I've commented that this part of it but that wasn't the problem.
The problem was I left out this curly braces here here it's very important that your curly braces to
match if not the cold will not run.
So I missed this one.
That's why I didn't run.
So I see they have to be paired that one Piers with that and they pay that if he's not pay it will not
run.
So let me run this quote and you can see when it starts says hooray I love chocolate ice cream because
the first condition here has been met saying if this condition is met a lot just messy if not alert
the sick on code.
So because this was conditional statements do enjoy have a scrip they used to test if a condition is
true or not and based on that the court specified or wrong so it doesn't run all the time because with
all Iran.
If the condition is met or right in is your.
I explained what conditional States means to be.
I used to run quantised cool based on certain conditions.
So if one condition is true it will execute one block of code and if the so forth condition is true
it executes the first block of call.
If is not true.
Execute the second block of code.
So this is how conditional statements work in JAMA scrip.
Thank you so much for watching.
I hope the EU has been useful.
Thank you.
Bye for now.